<?php

class Admin_Form_Apiupdate extends Zend_Form {

    public function init() {
        $this->mainForm($result = null);
    }

    public function mainForm($result) {
        $this->setAction('/admin/api/update')
                ->setMethod('post');

        //setting values
        $path = $result[0]['server_path'];
        $apiname = $result[0]['name'];
        $apikey = $result[0]['api_key'];
        $apisecret = $result[0]['api_secret'];
        $id = $result[0]['sr'];

        //api id
        $apiId = new Zend_Form_Element_Hidden('sr');
        $apiId->setValue($id);


        //server path
        $serverPath = new Zend_Form_Element_Text('server_path');
        $serverPath->setLabel('Server Path')
                ->setValue($path)
                ->setOptions(array('size' => '100'))
                ->addFilter('stringTrim');


        //api name
        $apiName = new Zend_Form_Element_Text('name', array('readonly' => 'readonly'));
        $apiName->setLabel('Api Name:')
                ->setValue($apiname)
                ->setOptions(array('size' => '30'))
                ->setRequired(true)
                ->addFilter('stringTrim');

        //api key
        $apiKey = new Zend_Form_Element_Text('api_key');
        $apiKey->setLabel('API KEY:')
                ->setValue($apikey)
                ->setOptions(array('size' => '50'))
                ->setRequired(true)
                ->addFilter('stringTrim');

        //api secret
        $apiSecret = new Zend_Form_Element_Text('api_secret');
        $apiSecret->setLabel('API Secret:')
                ->setValue($apisecret)
                ->setOptions(array('size' => '50'))
                ->setRequired(true)
                ->addFilter('stringTrim');

        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('Update')
                ->setOptions(array('class' => 'submit'))
                ->setAttrib('class', 'btn btn-success');


        //add to form
        $this->addElement($apiId)
                ->addElement($apiName)
                ->addElement($serverPath)
                ->addElement($apiKey)
                ->addElement($apiSecret)
                ->addElement($submit);
    }

}

